#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class MysteriousRestaurant {
public:
	int maxDays(vector <string>, int);
	int N;
	int M;
};

int MysteriousRestaurant::maxDays(vector <string> prices, int budget) {
	N = prices.size();
	M = prices[0].size();
	vector<vector<int> > v(7, vector<int>(M, 0));
	for(int i=0; i<N; i++){
		for(int j=0; j<M; j++){
			int a = i%7;
			int p;
			if(prices[i][j]>='0'&& prices[i][j]<='9') p = prices[i][j] - '0';
			if(prices[i][j]>='A'&& prices[i][j]<='Z') p = prices[i][j] - 'A' + 10;
			if(prices[i][j]>='a'&& prices[i][j]<='z') p = prices[i][j] - 'a' + 36;
			v[a][j] += p;
		}
	}
	int sum = 0;
	for(int i=0; i<7; i++){
		sort(v[i].begin(), v[i].end());
		for(int j=0; j<M; j++) cout << v[i][j] << ", ";
		cout << endl;
		if(budget >= v[i][0]) {
			sum++;
			budget-=v[i][0];
		}
		else break;
	}
	return sum;
}


double test0() {
	string t0[] = {"26", "14", "72", "39", "32", "85", "06"};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	int p1 = 13;
	MysteriousRestaurant * obj = new MysteriousRestaurant();
	clock_t start = clock();
	int my_answer = obj->maxDays(p0, p1);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p2 = 5;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p2 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p2 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test1() {
	string t0[] = {"26", "14", "72", "39", "32", "85", "06", "91"};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	int p1 = 20;
	MysteriousRestaurant * obj = new MysteriousRestaurant();
	clock_t start = clock();
	int my_answer = obj->maxDays(p0, p1);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p2 = 8;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p2 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p2 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test2() {
	string t0[] = {"SRM", "512"};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	int p1 = 4;
	MysteriousRestaurant * obj = new MysteriousRestaurant();
	clock_t start = clock();
	int my_answer = obj->maxDays(p0, p1);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p2 = 0;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p2 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p2 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test3() {
	string t0[] = {"Dear", "Code", "rsHa", "veFu", "nInT", "heCh", "alle", "ngeP", "hase", "andb", "ecar", "eful"};
	vector <string> p0(t0, t0+sizeof(t0)/sizeof(string));
	int p1 = 256;
	MysteriousRestaurant * obj = new MysteriousRestaurant();
	clock_t start = clock();
	int my_answer = obj->maxDays(p0, p1);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p2 = 10;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p2 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p2 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}

int main() {
	int time;
	bool errors = false;
	
	time = test0();
	if (time < 0)
		errors = true;
	
	time = test1();
	if (time < 0)
		errors = true;
	
	time = test2();
	if (time < 0)
		errors = true;
	
	time = test3();
	if (time < 0)
		errors = true;
	
	if (!errors)
		cout <<"You're a stud (at least on the example cases)!" <<endl;
	else
		cout <<"Some of the test cases had errors." <<endl;
}

//Powered by [KawigiEdit] 2.0!
